package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.entity.Visitor;
import com.face.server.service.impl.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("client/visitor")
public class VisitorController {

    @Autowired
    VisitorService visitorService;

    @PostMapping
    RespMsg save(@RequestBody Visitor visitor,
                 @RequestAttribute String id) {
        visitor.setType(1);
        return visitorService.save(visitor, id);
    }

    @GetMapping
    RespMsg findByStudentId(@RequestAttribute String id) {
        return visitorService.findByStudentId(id);
    }

    @GetMapping("{id}")
    RespMsg findById(@PathVariable String id) {
        return visitorService.findById(id);
    }


    @PostMapping("{id}/faceModels")
    RespMsg pushFaceModels(@PathVariable String id,
                           MultipartFile file) throws IOException {
        return file == null
                ? RespMsg.error("对不起，文件不能为空")
                : visitorService.saveFaceModels(file, id);
    }


}
